import { login } from '@/api/api'

export default {
    state: {
        isCollapse: false,
        tabList: [
            {
                path: '/home',
                name: 'home',
                lable: '主页',
                icon: 's-home',
            }
        ],
        result: {}
    },
    mutations: {
        collapseMenu(state) {
            state.isCollapse = !state.isCollapse
        },
        selectMenu(state, val) {
            var store = []
            const res = state.tabList.findIndex(item => item.name === val.name)
            if (res === -1) {
                console.log('插入item',state.tabList);
                state.tabList.push(val)
            }
            else {
                store = state.tabList
                console.log('oldtabList',state.tabList);
                console.log('oldstore',store);
                store.splice(res + 1, state.tabList.length - 1)
                console.log('newtabList',state.tabList);
            }

        },
    },
    actions: {
        // eslint-disable-next-line
        userReg({ commit }) {
            // const { username, password } = userInfo;
            return new Promise((resolve, reject) => {
                login()
                    .then(() => {
                        // console.log('res.data',res.data);
                    })
                    .catch((error) => {
                        reject(error);
                    });
            });
        },
    }
}